﻿using System;
using System.Collections.Generic;
using Assets.Scripts.PerformanceTuner;
using UnityEngine;
using UnityEngine.PostProcessing;

// Token: 0x02000319 RID: 793
[DisallowMultipleComponent]
public class PerformanceTuner : MonoBehaviour
{
	// Token: 0x06001426 RID: 5158 RVA: 0x00084B54 File Offset: 0x00082D54
	private void Start()
	{
		int qualityLevel = QualitySettings.GetQualityLevel();
		IPerformanceProfile performanceProfile = PerformanceTuner.GetPerformanceProfile(qualityLevel);
		IEnumerable<Light> lights = Resources.FindObjectsOfTypeAll<Light>();
		IEnumerable<ReflectionProbe> reflections = Resources.FindObjectsOfTypeAll<ReflectionProbe>();
		PerformanceTuner.SetLights(performanceProfile, lights);
		PerformanceTuner.SetReflections(performanceProfile, reflections);
	}

	// Token: 0x06001427 RID: 5159 RVA: 0x00084B88 File Offset: 0x00082D88
	private static void SetLights(IPerformanceProfile profile, IEnumerable<Light> lights)
	{
		foreach (Light light in lights)
		{
			light.shadows = profile.ShadowType;
			light.shadowResolution = profile.ShadowResolution;
		}
	}

	// Token: 0x06001428 RID: 5160 RVA: 0x00084BF0 File Offset: 0x00082DF0
	private static void SetReflections(IPerformanceProfile profile, IEnumerable<ReflectionProbe> reflections)
	{
		foreach (ReflectionProbe reflectionProbe in reflections)
		{
			reflectionProbe.hdr = profile.EnableHdr;
			reflectionProbe.resolution = profile.ReflectionResolution;
			reflectionProbe.shadowDistance = (float)profile.ShadowDistance;
		}
	}

	// Token: 0x06001429 RID: 5161 RVA: 0x00084C64 File Offset: 0x00082E64
	private static IPerformanceProfile GetPerformanceProfile(int qualityLevel)
	{
		Debug.Log("Overwriting scene lights and reflection to quality level " + qualityLevel);
		switch (qualityLevel)
		{
		case 0:
			return new Fastest();
		case 1:
			return new Fast();
		case 2:
			return new Simple();
		case 3:
			return new Good();
		case 4:
			return new Beautiful();
		case 5:
			return new Fantastic();
		default:
			Debug.LogError("Unkown profile error, reverting to 0!");
			return new Fastest();
		}
	}

	// Token: 0x0600142A RID: 5162 RVA: 0x00084CDC File Offset: 0x00082EDC
	public static void SetRenderEngine(int qualityLevel)
	{
		if (!GlobalPreferences.UseNewRenderEngine.value)
		{
			IEnumerable<Camera> enumerable = UnityEngine.Object.FindObjectsOfType<Camera>();
			foreach (Camera camera in enumerable)
			{
				camera.renderingPath = RenderingPath.Forward;
				camera.allowHDR = false;
				camera.allowMSAA = false;
			}
			if (QualitySettings.pixelLightCount > 4)
			{
				QualitySettings.pixelLightCount = 4;
			}
			Camera main = Camera.main;
			PostProcessingBehaviour component = main.GetComponent<PostProcessingBehaviour>();
			PostProcessingProfile profile = null;
			switch (qualityLevel)
			{
			default:
				component.enabled = false;
				break;
			case 1:
				profile = Resources.Load<PostProcessingProfile>("Presets/Fast");
				break;
			case 2:
			case 3:
				profile = Resources.Load<PostProcessingProfile>("Presets/Simple");
				break;
			case 4:
				profile = Resources.Load<PostProcessingProfile>("Presets/Beautiful");
				break;
			}
			component.profile = profile;
		}
	}
}
